package com.zhang.entity.response;

/**
 * Created with IntelliJ IDEA.
 * User: 张
 * Date: 2024-10-27
 * Time: 15:18
 * Description:
 */
public class ResponseResult <T> {
    private Integer code;
    private String msg;
    private T data;

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
    public ResponseResult(Integer code, String msg){
        this.code = code;
        this.msg = msg;
    }

    public ResponseResult(ResultCode resultCode){
        this.code = resultCode.getCode();
        this.msg = resultCode.getMsg();
    }
    public ResponseResult(ResultCode resultCode, T data) {
        this.code = resultCode.getCode();
        this.msg = resultCode.getMsg();
        this.data = data;
    }
    public static<T> ResponseResult<T> success(){
        return new ResponseResult<>(ResultCode.SUCCESS);
    }
    public static<T> ResponseResult<T> success(T data){
        return new ResponseResult<>(ResultCode.SUCCESS,data);
    }
    public static<T> ResponseResult<T> error(){
        return new ResponseResult<>(ResultCode.FAILED);
    }
    public static<T> ResponseResult<T> error(String msg){
        return new ResponseResult<>(ResultCode.FAILED.getCode(),msg);
    }


}
